<template>
  <div class="cont">
    <van-divider
      :style="{
        color: 'black',
        borderColor: 'black',
        padding: '0 45px',
      }"
    >
      热门推荐
    </van-divider>

    <van-grid :column-num="2">
      <van-grid-item v-for="item in hotlist" :key="item.id">
        <img :src="item.image" alt="" />
        <p>{{ item.storeName }}</p>
        <span class="allqian">
          <span class="qian">¥</span>
          {{ item.price }}
        </span>
      </van-grid-item>
      <van-loading class="more" v-if="loading"> 加载中.... </van-loading>
      <div v-else :disabled="hasmore" class="more" @click="getmore()">
        {{ hasmore ? "已经到底啦" : "加载更多" }}
      </div>
    </van-grid>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  
  data() {
    return {
      hotlist: [],
      pageNo: 0,
      hasmore: false,
      loading: false,
    };
  },
  created() {
    this.getHotGoods();
  },
  methods: {
    async getHotGoods() {
      if (this.hasmore !== false) {
        return;
      }
      ++this.pageNo;
      // const res = await this.$http.getHotGoods(this.pageNo);
      await axios
        .get(
          `https://api.java.crmeb.net/api/front/product/hot?page=${this.pageNo}&limit=8`
        )
        .then((res) => {
          this.hotlist = this.hotlist.concat(res.data.data.list);
          this.hasmore = res.data.data.total < this.pageNo * 8;
        });
      // this.hotlist = this.hotlist.concat(res.data.data.list);
      // this.hasmore = res.data.data.total < this.pageNo * 8;
    },
    getmore() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.getHotGoods();
      }, 1000);
    },
  },
};
</script>
<style lang="scss" scoped>
.cont {
  .van-grid {
    padding: 0px 4px;
  }
  .van-grid-item {
    p {
      font-size: 14px;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
    }
    span {
      color: red;
      font-size: 15px;
      font-weight: bold;
      .qian {
        font-size: 10px;
        margin-top: 4px;
        font-weight: 600;
      }
    }
    img {
      width: 167px;
      height: 167px;
      border-radius: 7px;
    }
  }
  .more {
    color: #969799;
    font-size: 12px;
    line-height: 40px;
    text-align: center;
    margin-bottom: 50px;
    width: 100%;
  }
}
</style>